package org.budo.jdbc.driver.resultset.impl;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;

import org.budo.jdbc.driver.BudoJdbcResultSetMetaData;

import lombok.Setter;

/**
 * 多列多行结果集
 * 
 * @author lmw
 */
public class MapArrayResultSet extends AbstractArrayResultSet<Map> {
    @Setter
    private boolean lastGotValueWasNull = false;

    public MapArrayResultSet() {}

    public MapArrayResultSet(ResultSetMetaData metaData, Map[] valueArray) {
        this.metaData(metaData);
        this.valueArray(valueArray);
    }

    public MapArrayResultSet(String[] columnNames, Map[] valueArray) {
        this(new BudoJdbcResultSetMetaData(columnNames), valueArray);
    }

    @Override
    protected Object getCellValue(String columnLabel) {
        int rowNumber = this.rowNumber();
        Map map = this.valueArray()[rowNumber];
        Object value = map.get(columnLabel);

        if (null == value) {
            this.setLastGotValueWasNull(true);
        }

        return value;
    }

    @Override
    public boolean wasNull() throws SQLException {
        return this.lastGotValueWasNull;
    }
}
